package com.jia.train.seat.controller;

import com.jia.train.global.page.PageResponse;
import com.jia.train.global.response.BaseResponse;
import com.jia.train.seat.request.TripsQueryRequest;
import com.jia.train.seat.request.TripsSaveRequest;
import com.jia.train.seat.response.TripsQueryResponse;
import com.jia.train.seat.response.TripsSaveResponse;
import com.jia.train.seat.service.TripsService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/trips")
public class TripsController {

    @Resource
    private TripsService tripsService;

    @PostMapping("/insert")
    public BaseResponse<TripsSaveResponse> insertTrips(@Valid @RequestBody TripsSaveRequest request) {
        TripsSaveResponse response = tripsService.insert(request);
        return new BaseResponse<>(response);
    }

    @GetMapping("/query")
    public BaseResponse<PageResponse<TripsQueryResponse>> query(@Valid TripsQueryRequest request) {
        PageResponse<TripsQueryResponse> responseList = tripsService.selectPage(request);
        return new BaseResponse<>(responseList);
    }

    @GetMapping("/list")
    public BaseResponse<List<TripsQueryResponse>> query() {
        List<TripsQueryResponse> responseList = tripsService.selectList();
        return new BaseResponse<>(responseList);
    }

    @DeleteMapping("/delete/{id}")
    public BaseResponse<String> delete(@PathVariable Long id) {
        tripsService.deleteTrips(id);
        return new BaseResponse<>("success");
    }

}
